#include <windows.h>
#include "SoundPotMainAudioEffect.h"


static AEffect* pluginEntryPoint (audioMasterCallback audioMaster)
{
    MessageManager::getInstance()->setTimeBeforeShowingWaitCursor (0);

    try
    {
        if (audioMaster (0, audioMasterVersion, 0, 0, 0, 0) != 0)
        {
			SoundPot::MainAudioEffect* const wrapper = new SoundPot::MainAudioEffect (audioMaster);
            return wrapper->getAeffect();

        }
    }
    catch (...)
    {}

    return 0;
}

//==============================================================================
// Mac startup code..
#ifdef JUCE_MAC

extern "C" __attribute__((visibility("default"))) AEffect* main_macho (audioMasterCallback audioMaster)
{
    initialiseJuce_GUI();
    return pluginEntryPoint (audioMaster);
}

//==============================================================================
// Linux startup code..
#elif JUCE_LINUX

extern "C" AEffect* main_plugin (audioMasterCallback audioMaster) asm ("main");

extern "C" AEffect* main_plugin (audioMasterCallback audioMaster)
{
    initialiseJuce_GUI();
    return pluginEntryPoint (audioMaster);
}

__attribute__((constructor)) void myPluginInit()
{
    // don't put initialiseJuce_GUI here... it will crash !
}

__attribute__((destructor)) void myPluginFini()
{
    // don't put shutdownJuce_GUI here... it will crash !
}

//==============================================================================
// Win32 startup code..
#else

__declspec(dllexport) void* main (audioMasterCallback audioMaster)
{
    return (void*) pluginEntryPoint (audioMaster);
}

BOOL WINAPI DllMain (HINSTANCE instance, DWORD dwReason, LPVOID)
{
    if (dwReason == DLL_PROCESS_ATTACH)
    {
        PlatformUtilities::setCurrentModuleInstanceHandle (instance);
        initialiseJuce_GUI();
    }
    else if (dwReason == DLL_PROCESS_DETACH)
    {
        shutdownJuce_GUI();
    }

    return TRUE;
}

#endif